<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>0914</title>
  </head>
  <body>
    <script type="module">
        // 	2180891
      function formatDate(time) {
        const date=new Date(time)
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份是从0开始的，所以加1
        const day = String(date.getDate()).padStart(2, "0");
        const hours = String(date.getHours()).padStart(2, "0");
        const minutes = String(date.getMinutes()).padStart(2, "0");
        const seconds = String(date.getSeconds()).padStart(2, "0");

        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
      }
      const uniqueData = (arr) => {
        const timedata = removeDuplicatesByTime(arr);
        const result = Object.values(
          timedata.reduce((acc, { uid, time, lv, content }) => {
            if (!acc[uid]) {
              acc[uid] = { uid, content: "", time, lv };
            }
            if (!acc[uid].content) {
              acc[uid].content = content;
            } else {
              acc[uid].content = acc[uid].content + "," + content;
            }
            // 拼接内容
            return acc;
          }, {})
        );
        return result.map((i) => ({
          ...i,
          timestr: formatDate(i.time),
        }));
      };
      function removeDuplicatesByTime(arr) {
        const seenTimes = new Set(arr.map((item) => item.time));
        return [...seenTimes].map((time) =>
          arr.find((item) => item.time === time)
        );
      }
      fetch("./lvyin.json")
        .then((response) => response.json())
        .then((data) => {
          console.table(uniqueData(data), ["content", "uid", "timestr",'time']);
        })
        .catch((error) => console.error("Error:", error));
    </script>
  </body>
</html>
